<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
	<head>
		<script src="./system/mootools-1.2.4.js" type="text/javascript"> 			</script>
		<script src="./system/moretools-1.2.4.js" type="text/javascript"> 			</script>

					<!-- Include helper classes -->					
				<script src="./main/main.js" type="text/javascript"> 				</script>
	
					<!-- Include base classes -->	
				<script src="./main/model/Model.js" type="text/javascript"> 		</script> 
				<script src="./main/control/Control.js" type="text/javascript"> 	</script> 
			
					<!-- Include Model classes -->
				<script src="./main/model/project.js" type="text/javascript"> 		</script> 
				<script src="./main/model/group.js" type="text/javascript"> 		</script> 
				<script src="./main/model/user.js" type="text/javascript"> 			</script> 
				<script src="./main/model/target.js" type="text/javascript"> 	</script> 
				<script src="./main/model/ticket.js" type="text/javascript"> 		</script> 
			
					<!-- Include Control classes -->			
				<script src="./main/control/projects.js" type="text/javascript"> 	</script> 
				<script src="./main/control/groups.js" type="text/javascript"> 		</script> 
				<script src="./main/control/users.js" type="text/javascript">		</script> 
				<script src="./main/control/targets.js" type="text/javascript"> 	</script> 
				<script src="./main/control/tickets.js" type="text/javascript"> 	</script> 
				
					<!-- Include core classes -->					
				<script src="./main/core.js" type="text/javascript"> </script>
				
		
		<script type="text/javascript">

				//Mootools gives us this once its done loading the document and scripts
			window.addEvent('domready', function() 
			{
				startSystemTest.delay(2000);
			});	
		
			var startSystemTest = function()
			{
					//This handles the entire interaction with the teamctrl core.
				core = new teamCtrl();
				
					//At this point all entities are pretty generic,and any and all properties assigned in the below JSON object
					//will define what the instance contains. This is to demonstrate the flexibility of the framework, 
					//and the simplicity of the update/frontend interaction.
				var m = new Target( up( " { name:'v1.0 of teamctrl framework', deadline:'today', desc:'Fully functional project management software framework with working examples of all tasks (and database interaction).'} " ) );
				var t = new Ticket( up( " { name:'Complete task templates.', progress:'0', info:'Finalise task templates to contain subtasks via a single controller.', assignedto:'1'} " ) );
				var p = new Project( up( " { name:'P1', desc:'Project description describing the very essence of this project.'} " ) );
				var g = new Group( up( " { name:'Artists', desc:'Art team for project X', shortname:'XBT'} " ) );
				
					var u = Array();
					var ul = '';
				
					//Create some users and add them to a project
				for(i = 0; i < 4; i++)
				{
						//Supermessy crap hacks.
					var d = new Date();  d = ''+d;
						u[i] = new User( up( " { name:'U"+i+"', type:'Producer', email:'User"+i+"@company.com', pwhash:'no', lastlogin:'"+d+"', accesslevel:'0', status:'No tasks assigned.', groups:'"+i+"', currentticket:'6' } " ) );
					
						//Add the user to the controller
					core.users.add(u[i]);
						//Update the user list string for the project
					ul += u[i].id + ' ';
				}
				
					//Users can be assigned to projects and so on, 
					//Lets assign them. In the debug output, all the entities pointing to other 
					//entities in the system will be ID based.
				p.assignUsers(ul);
				
				core.targets.add(m);
				core.tickets.add(t);				
				core.projects.add(p);
				core.groups.add(g);
				
					//The actual interaction with the software should/can be from simple request strings.
					//For example, a simple client can just send a simple POST string, to a single script, with
					// no intermediate code required for the system to work.
				happen("Project add { name:'RemoteAdd', desc:'Added via the happen function (simulating a network interaction to the system).'}");
				
						//The functions inside the controllers, toStr() and toStrAll() are for debugging the
						//contents in the system at any given point.
						
					str = 'And in 5 seconds an alert will popup the test project information.';
					str += '<br /> <br />';
						
					str += core.targets.toStrAll();
					str += core.tickets.toStrAll();
					str += core.users.toStrAll();
					str += core.projects.toStrAll();
					str += core.groups.toStrAll();
					
					//Assign it to the document
				$('test').innerHTML = str;
				
					//Fetch a project and test the return.
					//Fetch, and toStr use a string separated list of items.
					// fetch 1 2 5 fetches only those, and only if they exist.
					// if you fetch 3, and object with id of 3 does not exist,
					// the result is an empty array.
				var testP = happen("Project fetch 2")[0];
				showProject.delay(5000, '', testP);			
			}

				//A simple function for displaying a project name and description
			var showProject = function(p)
			{
					//Make a string
				var tmpstr = 'Project : ' + p.name;
				tmpstr += '\n\n';
				tmpstr += 'Desc : \n' + p.desc;
					//Show the info
				alert(tmpstr);
			}
			
		
		</script>
		
	</head>
	
	<body>
		<div id="test">
			In 2 Seconds this page will output all the test data in the system.
			
		</div>
	</body>
	
</html>